package com.testfileupload.uploadimg.design.chainofresponsibility.correct;


public abstract class Handler {
    public final static int FATHER_LEVEL_REQUEST = 1;
    public final static int HUSBAND_LEVEL_REQUEST = 2;
    public final static int SON_LEVEL_REQUEST = 3;
    //能处理的级别
    private int level = 0;
    //责任传递，下一个责任人是谁
    private Handler nextHandle;
    //每个类要说明自己能处理那些请求

    public Handler(int level) {
        this.level = level;
    }

    //一个女性(女儿、妻子、母亲)要求逛街，你要处理这个请求
    public final void handleMessage(IWomen women) {
        if (women.getType() == level) {
            this.response(women);
        } else {
            if (this.nextHandle != null) {
                this.nextHandle.handleMessage(women);
            } else {
                System.out.println("没有请示人，按不同意处理");
            }
        }
    }

    //设置下一个处理环节是谁
    void setNext(Handler handler) {
        this.nextHandle = handler;
    }

    //回应
    protected abstract void response(IWomen iWomen);
}
